//展示索引的详细信息
function showIndex(id){
	clearAddFrame();
	$('#rightInDiv').removeClass('HdClass');
	$('#rightDiv').removeClass('HdClass');
	$('#addIndexDiv').addClass('HdClass');
	$('#indexTitleshowDiv').addClass('HdClass');
	$.ajax({
		url:"selectIndexPermission.action",
		data:{id:id},
		dataType:"JSON",
		type:"POST",
		success:function(data){
			var se = data.se;
			var list = data.list;
			var indexName = "<div style='float:left;width:33.33333333%;padding-left:1%;'>"
				+"<div style='float:left;'><label>索引名称：</label></div>"
				+"<div style='float:left;padding-top:0px;cursor:default;'><div>"+se.searchName+"</div></div></div>";
			var indexType = "";
			if(list.length>0){
				indexType = "<div style='float:left;width:33.33333333%;' id='indexTypeshow'>"
					+"<div style='float:left;'><label>索引类型：</label></div>"
					+"<div style='float:left;padding-top:0px;cursor:default;'>";
				var type = "";
				$.each(list,function(i,obj){
					type += "<div onclick=showIndexTitle('"+obj.id+"');>"+obj.search_types+"</div>";
				});
				indexType += type;
				indexType += "</div></div>";
				indexType += "<div style='float:left;width:33.33333333%;cursor:default' id='indexTitleshowDiv' class='HdClass'>"
					+"<div style='float:left;'><label>索引标题：</label></div>"
					+"<div style='float:left;padding-top:0px;' id='indexTitleshow'></div></div>";
			}else{
				indexType = "<div style='float:left;width:33.33333333%;' id='indexTypeshow'>"
					+"<div style='float:left;'><label>索引类型：</label></div><div style='float:left;cursor:default;color:red;'>没有关联的索引类型</div></div>";
			}
			indexName += indexType;
			indexName += "<div style='clear:both;'></div>";
			document.getElementById("rightInDiv").innerHTML = '';
			document.getElementById("rightInDiv").innerHTML += indexName;
			
		},
		error:function(e){
			alert("展示索引详细信息时异常："+e.status);
		}
	});
}
function showIndexTitle(id){
	$.ajax({
		url:"selectIndexTitleByPid.action",
		data:{id:id},
		dataType:"JSON",
		type:"post",
		success:function(data){
			var title = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					title += "<div onclick=showIndexFieldPermission('"+obj.pid+"','"+obj.search_title+"','show')>"+obj.search_title+"</div>";
				});
			}else{
				title += "<div style='color:red;'>没有关联的索引标题</div>";
			}
			$('#indexTitleshowDiv').removeClass('HdClass');
			document.getElementById("indexTitleshow").innerHTML = '';
			document.getElementById("indexTitleshow").innerHTML += title;
		},
		error:function(e){
			alert("查询标题时异常...:"+e.status);
		}
	});
}
var index = ['store','term_vector','analyzer','searchAnalyzer','include_in_all','boost'];
function showIndexFieldPermission(pid,title,functionType){
	$.ajax({
		url:"selectIndexFieldByPid.action",
		data:{pid:pid,
			title:title},
		dataType:"JSON",
		type:"post",
		success:function(data){
			$('#myModalshow').modal('show');
			var t = "";
			if('u' == functionType){
				//修改
				t += "<label style='float:left'>索引标题：</label><input type='text' value='"+title+"' id='updateIndexTitleInputModal'/><div style='clear:both;'></div>";
				$('#updateIndexTitle_oldTitle').val(title);
				$('#updateIndexTilte_oldPid').val(pid);
				$('#confirmUpdateTitleButton').removeClass('HdClass');
			}else{
				t += "<label style='float:left'>索引标题：</label><div>"+title+"</div><div style='clear:both;'></div>";
			}
			document.getElementById('showIndexTitle').innerHTML = '';
			document.getElementById('showIndexTitle').innerHTML += t;
			if(data.length>0){
				$.each(data,function(i,obj){
					for(var j=0;j<index.length;j++){
						if(index[j] == obj.search_field){
							document.getElementById(index[j]+'3').checked=true;
							$("#"+index[j]+'2'+" option[value='"+obj.search_field_type+"']").prop("selected",true);
						}
					}
				});
			}
		},
		error:function(e){
			alert("查询索引明细时异常："+e.status);
		}
	});
}

//打开新增索引页面
function addIndex(){
	$('#rightDiv').removeClass('HdClass');
	$('#rightInDiv').addClass('HdClass');
	$('#addIndexDiv').removeClass('HdClass');
	
}

//添加索引列完成
function confirmAddIndex(){
	//var HDNTT_id = $("#HDNTT_id").val();
	if(confirm("确定添加索引完成？")){
		var indexType_id = $('#indexType_whenmapping option:checked').val();
		$.ajax({
			url:"checkIndexFieldPermissionOnIndexType.action",
			data:{indexType_id:indexType_id},
			dataType:"JSON",
			type:"POST",
			success:function(data){
				if(data){
					$('#myModalFinish').modal('show');
					$.ajax({
						url:"addIndexFinish.action",
						data:{indexType_id:indexType_id},
						dataType:"JSON",
						type:"POST",
						success:function(data){
							$('#myModalFinish').modal('hide');
							alert("添加索引成功！");
						},
						error:function(e){
							alert("添加索引完成时异常："+e.status);
							$('#myModalFinish').modal('hide');
						}
					})
					//window.location.href = "showAllIndex.action";
				}else{
					alert("该索引类下无索引标题和列，请添加索引标题和列！");
				}
			},
			error:function(e){
				alert("查询索引列时异常："+e.status);
			}
		})
	}

}
//清除面板
function clearAddFrame(){
	$('#addIndexDiv').addClass('HdClass');
	$('#showDeleteIndexName').addClass('HdClass');
	
	$('#rightDiv').addClass('HdClass');
	$('#rightInDiv').addClass('HdClass');
	$('#showDeleteIndexType').addClass('HdClass');
	
	$('#operationModal').modal('hide');
	$('#showDeleteIndexTitle').addClass('HdClass');
	$('#showUpdateIndexName').addClass('HdClass');
	$('#showUpdateIndexType').addClass('HdClass');
	$('#showUpdateIndexTitle').addClass('HdClass');
	$('#confirmUpdateTitleButton').addClass('HdClass');
	document.getElementById('indexNameSelect').innerHTML = '';
	
	$('#addIndexName').val('');
	$('#addIndexType').val('');
	$('#updateIndexTypeModal_input').val('');
	$('#updateIndexNameIdModal_input').val('');
	$('#addIndexTitle').val('');
	
}
function clearShowFrame(){
	for(var i=0;i<index.length;i++){
		document.getElementById(index[i]+'3').checked=false;
	}
	$("#store2 option[value='no']").prop("selected",true);
	$("#term_vector2 option[value='no']").prop("selected",true);
	$("#analyzer2 option[value='ik']").prop("selected",true);
	$("#searchAnalyzer2 option[value='ik']").prop("selected",true);
	$("#include_in_all2 option[value='true']").prop("selected",true);
	$("#boost2 option[value='1']").prop("selected",true);
	$('#confirmUpdateTitleButton').addClass('HdClass');
	document.getElementById('updateIndexTitle_showExit').innerHTML = '';
}
function justClearAddIndexFrame(){
	$('#addIndexTitle').val('');
	$("#store option[value='no']").prop("selected",true);
	$("#term_vector option[value='no']").prop("selected",true);
	$("#analyzer option[value='ik']").prop("selected",true);
	$("#searchAnalyzer option[value='ik']").prop("selected",true);
	$("#include_in_all option[value='true']").prop("selected",true);
	$("#boost option[value='1']").prop("selected",true);
	$("#addIndexFT div input:checked").each(function(){
		$(this).prop("checked",false);
	});
}

//打开新增索引名称面板
function addIndexName(){
	clearAddFrame();
	$('#addIndexF').addClass('HdClass');
	$('#sysEsclientThree').removeClass('HdClass');
	$('#rightDiv').removeClass('HdClass');
	$('#addIndexDiv').removeClass('HdClass');
	$('#addIndexTypeDiv').addClass('HdClass');
}
function addIndexNameData(){
	if(confirm("确认新增索引名称吗？")){
		var addIndexName = $('#addIndexName').val();
		if('' == addIndexName){
			alert("请输入索引名称！");
		}else{
			$.ajax({
				url:"checkIndexNameSame.action",
				data:{addIndexName:addIndexName},
				dataType:"JSON",
				type:"POST",
				success:function(data){
					if(data){
						alert("索引"+addIndexName+"已经存在，请重新输入。");
					}else{
						$.ajax({
							url:"addIndex.action",
							data:{addIndexName:addIndexName},
							dataType:"JSON",
							type:"POST",
							success:function(data){
								if(data != 0){
									alert("新增索引名称成功！");
								}else{
									alert("新增索引名称失败！");
								}
								showIndex(data);
								clearAddFrame();
								reLoadIndexName("");
								$("#rightDiv").removeClass('HdClass');
								$("#rightInDiv").removeClass('HdClass');
							},
							error:function(e){
								alert("新增索引名称时异常："+e);
							}
						});
					}
				},
				error:function(e){
					alert("检查索引名称时异常："+e.status);
				}
			})
			
		}
	}
	
}

//新增索引类型
function addIndexType(){
	clearAddFrame();
	$('#addIndexF').addClass('HdClass');
	$('#addIndexTypeDiv').removeClass('HdClass');
	$('#rightDiv').removeClass('HdClass');
	$('#addIndexDiv').removeClass('HdClass');
	$('#sysEsclientThree').addClass('HdClass');
	document.getElementById('indexNameSelect').innerHTML = '';
	$.ajax({
		url:"selectIndexNameWhenAddIndexType.action",
		data:{},
		dataType:"JSON",
		type:"POST",
		success:function(data){
			var t = "<select class='selectClass' id='addIndexType_selectId' onmouseleave='addIndexType_showExitType();'>";
			var te = "";
			if(data.length>0){
				$.each(data,function(i,obj){
					te += "<option value='"+obj.id+"'>"+obj.search_name+"</option>";
					
				});
			}
			t += te;
			t += "</select>";
			document.getElementById("indexNameSelect").innerHTML = '';
			document.getElementById("indexNameSelect").innerHTML += t;
		},
		error:function(e){
			alert("新增索引类型时查询索引名称异常："+e.status);
		}
	});
}
////////////////////////
function addIndexType_showExitType(){
	var id = $('#addIndexType_selectId').val();
	$.ajax({
		url:"selectIndexTypeWhenDeleteIndexType.action",
		data:{id:id},
		dataType:"json",
		type:"post",
		success:function(data){
			var t = "";
			var text = "";
			if(data.length>0){
				t += "<select class='selectClass'>";
				$.each(data,function(i,obj){
					text += "<option>"+obj.search_types+"</option>";
				});
				t += text;
				t += "</select>";
			}else{
				t += "<font color='red'>没有关联的索引类型</font>";
			}
			
			document.getElementById('indexTypeExit').innerHTML = '';
			document.getElementById('indexTypeExit').innerHTML += t;
		},
		error:function(e){
			alert("新增索引类型时查询已有类型异常："+e.status);
		}
	});
}

function addIndexTypeData(){
	if(confirm("确认新增索引类型？")){
		//索引名称id
		var index_id = $('#indexNameSelect option:checked').val();
		var indexNameSelect = $('#indexNameSelect').val();
		var indexType = $('#addIndexType').val();
		if(''==indexType){
			alert('请输入索引类型！');
		}else{
			$.ajax({
				url:"checkIndexTypeSame.action",
				data:{index_id:index_id,
					indexType:indexType},
				dataType:"JSON",
				type:"POST",
				success:function(data){
					if(data){
						alert("索引类型“"+indexType+"”在“"+indexNameSelect+"”下已存在，请重新输入。");
					}else{
						$.ajax({
							url:"justAddIndexName.action",
							data:{index_id:index_id,
								indexType:indexType},
							dataType:"JSON",
							type:"POST",
							success:function(data){
								if(!data)alert("新增索引类型失败！");
								addIndexType_showExitType();
								//window.location.href = "showAllIndex.action";
							},
							error:function(e){
								alert("新增索引类型时异常："+e.status);
							}
						})
					}
				},
				error:function(e){
					alert("检查索引类型时异常："+e.status);
				}
			});
		}
	}
}

//打开添加索引映射面板
function addIndexMapping(){
	clearAddFrame();
	document.getElementById('indexType_whenmapping').innerHTML = '';
	$('#rightDiv').removeClass('HdClass');
	$('#addIndexDiv').removeClass('HdClass');
	$('#rightInDiv').addClass('HdClass');
	$('#sysEsclientThree').addClass('HdClass');
	$('#addIndexTypeDiv').addClass('HdClass');
	$('#addIndexF').removeClass('HdClass');
	$.ajax({
		url:"selectIndexNameAndTypeWhenAddIndexField.action",
		data:"",
		dataType:"JSON",
		type:"POST",
		success:function(data){
			
			if(data.length>0){
				$.each(data,function(i,obj){
					if(null != obj.search_types && '' != obj.search_types){
						var op = document.createElement('option');
						op.setAttribute("value",obj.id);
						op.appendChild(document.createTextNode(obj.search_types));
						document.getElementById('indexType_whenmapping').appendChild(op);
					}
				})
			}
		},
		error:function(e){
			alert("新增索引映射时，查询索引名称和类型时异常："+e.status);
		}
	})
}
function addIndexMappingData(){
	
	var indexType_id = $('#indexType_whenmapping option:checked').val();
	var addIndexTitle = $('#addIndexTitle').val();
	var exsitTitle = $('#exsitTitle').text();
	var field = '';
	var fieldType = '';
	$("#addIndexFT div input:checked").each(function(){
		field += $(this).val()+",";
		fieldType += $("#"+$(this).val()).val()+",";
	})

	if(null == addIndexTitle || addIndexTitle == ''){
		alert("请填写索引标题！");
	}else if(field == ''){
		alert("请勾选索引列类型！");
	}else{
		$.ajax({
			url:"selectTheSameTitle.action",
			data:{id:indexType_id,
				title:addIndexTitle},
			dataType:"JSON",
			type:"post",
			success:function(data){
				if(data){
					document.getElementById('addIndexTitle_showTheSame').innerHTML = "<font color='red';>索引标题已经存在，请重新输入。</font>";
				}else{
					$.ajax({
						url:"justAddIndexMapping.action",
						data:{indexType_id:indexType_id,
							addIndexTitle:addIndexTitle,
							field:field,
							fieldType:fieldType},
						dataType:"JSON",
						type:"POST",
						success:function(data){
							if('' != data){
								if('' == exsitTitle){
									$('#exsitTitle').text(data+'、');
								}else{
									$('#exsitTitle').text($('#exsitTitle').text()+data+'、');
								}
							}else{
								alert("新增索引标题和列失败！");
							}
							
						},
						error:function(e){
							alert("新增索引标题和列时异常！"+e.status);
						}
					})
				}
			},
			error:function(e){
				alert("新增索引标题时，验证异常："+e.status);
			}
		});
		
	}
}

function selectIndexNameById(){
	var id = $('#indexType_whenmapping option:checked').val();
	if(null != id && '' != id){
		$.ajax({
			url:"selectNameById.action",
			data:{id:id},
			dataType:"JSON",
			type:"POST",
			success:function(data){
				var str = data.str;
				var str_title = data.str_title;
				document.getElementById('indexName_whenmapping').innerHTML = '';
				document.getElementById('indexName_whenmapping').innerHTML += str;
				$('#exsitTitle').text(str_title);
			},
			error:function(e){
				alert("查询索引名称时异常："+e.status);
			}
		})
	}
}
var indexOperationButton=['insertOperation','updateOperation','deleteOperation'];
//返回
function returnOperation(){
	$('#returnButton').hide();
	for(var i=0;i<indexOperationButton.length;i++){
		$("#"+indexOperationButton[i]).show();
	}
	for(var i=1;i<4;i++){
		$('#insertOperation'+i).addClass('HdClass');
	}
	for(var i=1;i<4;i++){
		$('#updateOperation'+i).addClass('HdClass');
	}
	for(var i=1;i<4;i++){
		$('#deleteOperation'+i).addClass('HdClass');
	}
}

//新增
function showInsertOperation(){
	$('#returnButton').show();
	for(var i=0;i<indexOperationButton.length;i++){
		$("#"+indexOperationButton[i]).hide();
	}
	for(var i=1;i<4;i++){
		$('#insertOperation'+i).removeClass('HdClass');
	}
}

//修改
function showUpdateOperation(){
	$('#returnButton').show();
	for(var i=0;i<indexOperationButton.length;i++){
		$("#"+indexOperationButton[i]).hide();
	}
	for(var i=1;i<4;i++){
		$('#updateOperation'+i).removeClass('HdClass');
	}
}

//删除
function showDeleteOperation(){
	$('#returnButton').show();
	for(var i=0;i<indexOperationButton.length;i++){
		$("#"+indexOperationButton[i]).hide();
	}
	for(var i=1;i<4;i++){
		$('#deleteOperation'+i).removeClass('HdClass');
	}
}

//删除索引名称
function deleteIndexName(){
	clearAddFrame();
	$('#rightDiv').removeClass('HdClass');
	$('#showDeleteIndexName').removeClass('HdClass');
	$.ajax({
		url:"selectIdAndNameWhenDelete.action",
		data:{},
		dataType:"json",
		type:"post",
		success:function(data){
			var text = "<label style='float:left;margin-top:13px;'>索引名称：</label><div style='float:left;cursor:default;'>";
			var t = "";
			if(data.length>0){
				$.each(data,function(i,obj){
					t += "<div onclick=\"deleteIndexNameData('"+obj.id+"','"+obj.search_name+"');\">"+obj.search_name+"</div>";
				});
			}else{
				t += "<div style='color:red;'>没有索引名称</div>";
			}
			text += t;
			text += "</div>";
			document.getElementById('showDeleteIndexName').innerHTML = '';
			document.getElementById('showDeleteIndexName').innerHTML += text;
		},
		error:function(e){
			alert("删除索引名称之查询索引名称异常："+e.status);
		}
	})
}
function deleteIndexNameData(id,name){
	$("#deleteNameTypeTitle_Modal").modal('show');
	$("#deleteNameTypeTitle_input").val(id);
	$("#deleteNameTypeTitle_inputV").val(1);
	var text = "确定要删除索引名称“"+name+"”吗？这会将其所属的索引类和索引标题一并删除。";
	document.getElementById('deleteNameTypeTitle_div').innerHTML = '';
	document.getElementById('deleteNameTypeTitle_div').innerHTML += text;
}
function deleteIndexNameData2(){
	var id = $("#deleteNameTypeTitle_input").val();
	$.ajax({
		url:"deleteIndexName.action",
		data:{id:id},
		dataType:"json",
		type:"post",
		success:function(data){
			if(!data)alert("删除失败！");
			deleteIndexName();
			reLoadIndexName("");
		},
		error:function(e){
			alert("删除索引名称时异常："+e.status);
		}
	})
}

function deleteIndexType(){
	clearAddFrame();
	$('#rightDiv').removeClass('HdClass');
	$('#showDeleteIndexType').removeClass('HdClass');
	$.ajax({
		url:"selectIndexNameWhenDeleteIndexType.action",
		data:"",
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引名称：</label></div>"
				+"<div><select class='selectClass' id='selectIndexNameWhenDeleteIndexType' onmouseleave='selectIndexNameWhenDeleteIndexType();'>";

			var op = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					op += "<option value='"+obj.id+"'>"+obj.search_name+"</option>";
				});
			}
			t += op;
			t += "</select></div></div>";
			t += "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引类型：</label></div>"
				+"<div style='float:left;padding-top:0px;cursor: default' id='showDeleteType'></div></div>"
			document.getElementById('showDeleteIndexType').innerHTML = '';
			document.getElementById('showDeleteIndexType').innerHTML += t;
		},
		error:function(e){
			alert("删除索引类型时查询索引名称异常："+e.status);
		}
	})
}
function selectIndexNameWhenDeleteIndexType(){
	var id = $("#selectIndexNameWhenDeleteIndexType option:checked").val();
	$.ajax({
		url:"selectIndexTypeWhenDeleteIndexType.action",
		data:{id:id},
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = "";
			if(data.length>0){
				$.each(data,function(i,obj){
					t += "<div onclick=\"deleteIndexTypeData('"+obj.id+"','"+obj.search_types+"');\">"+obj.search_types+"</div>";
				});
			}else{
				t += "<div style='color:red'>没有关联的索引类型<div>";
			}
			document.getElementById('showDeleteType').innerHTML = '';
			document.getElementById('showDeleteType').innerHTML += t;
		},
		error:function(e){
			alert("删除索引类型时查询索引类型异常："+e.status);
		}
	});
}
//删除索引类型
function deleteIndexTypeData(id,type){
	$("#deleteNameTypeTitle_Modal").modal('show');
	$("#deleteNameTypeTitle_input").val(id);
	$("#deleteNameTypeTitle_inputV").val(2);
	var text = "确认删除索引类型”"+type+"“吗？其所属索引标题也会一并删除！";
	document.getElementById('deleteNameTypeTitle_div').innerHTML = '';
	document.getElementById('deleteNameTypeTitle_div').innerHTML += text;
}
function deleteIndexTypeData2(){
	var id = $("#deleteNameTypeTitle_input").val();
	$.ajax({
		url:"deleteIndexType.action",
		data:{id:id},
		dataType:"JSON",
		type:"post",
		success:function(data){
			if(!data)alert("删除索引类型失败！");
			selectIndexNameWhenDeleteIndexType();
		},
		error:function(e){
			alert("删除索引类型时异常："+e.status);
		}
	});
}

//删除索引标题
function deleteIndexTitle(){
	clearAddFrame();
	$('#rightDiv').removeClass('HdClass');
	$('#showDeleteIndexTitle').removeClass('HdClass');
	$.ajax({
		url:"selectIndexNameWhenDeleteIndexType.action",
		data:"",
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引名称：</label></div>"
				+"<div style='float:left'><select class='selectClass' id='deleteIndexTitle_indexName' onmouseleave='deleteIndexTitle_showIndexType();'>";
			var str = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					str += "<option value='"+obj.id+"'>"+obj.search_name+"</option>";
				});
			}
			t += str;
			t += "</select></div></div>";
			t += "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引类型：</label></div>"
				+"<div style='float:left'><select class='selectClass HdClass' id='deleteIndexTitle_indexType' onmouseleave='deleteIndexTitle_showIndexTitle();'></select></div></div>";
			//标题
			t += "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引标题：</label></div>"
				+"<div style='float:left;cursor:default;padding-top:0px;' id='deleteIndexTitle_indexTitle'></div></div>";
			document.getElementById('showDeleteIndexTitle').innerHTML = '';
			document.getElementById('showDeleteIndexTitle').innerHTML += t;
		},
		error:function(e){
			alert("删除索引标题时查询索引名称异常："+e.status);
		}
	});
}
function deleteIndexTitle_showIndexType(){
	var nameId = $("#deleteIndexTitle_indexName option:checked").val();
	if(null != nameId && '' != nameId){
		$.ajax({
			url:"selectIndexTypeWhenDeleteIndexType.action",
			data:{id:nameId},
			dataType:"JSON",
			type:"post",
			success:function(data){
				var t = "";
				if(data.length>0){
					$('#deleteIndexTitle_indexType')[0].style.color = "";
					$.each(data,function(i,obj){
						t += "<option value='"+obj.id+"'>"+obj.search_types+"</option>";
					});
				}else{
					t += "<option value='' style='color:#D11718'>没有关联的索引类型</option>";
					$('#deleteIndexTitle_indexType')[0].style.color = "red";
				}
				$('#deleteIndexTitle_indexType').removeClass('HdClass');
				document.getElementById('deleteIndexTitle_indexType').innerHTML = '';
				document.getElementById('deleteIndexTitle_indexType').innerHTML += t;
				if(data.length<=0){
					
				}
			},
			error:function(e){
				alert("删除索引标题时查询索引类型异常："+e.status);
			}
		});
	}

}
function deleteIndexTitle_showIndexTitle(){
	var typeId = $("#deleteIndexTitle_indexType option:checked").val();
	if(null != typeId && '' != typeId){
		$.ajax({
			url:"selectIndexTitleByPid.action",
			data:{id:typeId},
			dataType:"JSON",
			type:"post",
			success:function(data){
				var t = '';
				if(data.length>0){
					$.each(data,function(i,obj){
						t += "<div onclick=\"deleteIndexTitle_delete('"+obj.pid+"','"+obj.search_title+"');\">"+obj.search_title+"</div>";
					});
				}else{
					t += "<div style='color:red;'>没有关联的索引标题</div>";
				}
				document.getElementById('deleteIndexTitle_indexTitle').innerHTML = '';
				document.getElementById('deleteIndexTitle_indexTitle').innerHTML += t;
			},
			error:function(e){
				alert("删除索引标题时查询索引标题异常："+e.status);
			}
		});
	}
}
function deleteIndexTitle_delete(pid,title){
	$("#deleteNameTypeTitle_Modal").modal('show');
	$("#deleteNameTypeTitle_input").val(pid);
	$("#deleteNameTypeTitle_inputV").val(3);
	$("#deleteNameTypeTitle_title").val(title);
	var text = "确认删除索引标题“"+title+"”吗？";
	document.getElementById('deleteNameTypeTitle_div').innerHTML = '';
	document.getElementById('deleteNameTypeTitle_div').innerHTML += text;

}
function deleteIndexTitle_delete2(){
	var pid = $("#deleteNameTypeTitle_input").val();
	var title = $("#deleteNameTypeTitle_title").val();
	$.ajax({
		url:"deleteTitleByPidAndTitle.action",
		data:{pid:pid,
			title:title},
		dataType:"JSON",
		type:"post",
		success:function(data){
			if(!data)alert("删除索引标题“"+title+"”失败！");
			deleteIndexTitle_showIndexTitle();
		},
		error:function(e){
			alert("删除索引标题时异常："+e.status);
		}
	})
}

//重新加载左边索引名称
function reLoadIndexName(text){
	$.ajax({
		url:"selectIndexNameWhenAddIndexType.action",
		data:{name:text},
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					t += "<tr><td onclick='showIndex("+obj.id+")'>"+obj.search_name+"</td></tr>";
				});
			}else{
				t += "<tr><td style='color:red;'>没有索引名称</td></tr>";
			}
			$("#indexTable_tbody").empty();
			document.getElementById('indexTable_tbody').innerHTML += t;
		},
		error:function(e){
			alert("查询左边索引名称时异常："+e.status);
		}
	})
}

//修改索引名称
function updateIndexName(){
	clearAddFrame();
	$('#rightDiv').removeClass('HdClass');
	$('#showUpdateIndexName').removeClass('HdClass');
	$.ajax({
		url:"selectIndexNameWhenAddIndexType.action",
		data:"",
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = "<label style='float:left;margin-top:7px;'>索引名称：</label><div style='float:left;padding-top:0px;cursor:default;'>";
			var tx = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					tx += "<div onclick=\"updateIndexNameModal('"+obj.id+"','"+obj.search_name+"');\">"+obj.search_name+"</div>";
				});
			}
			t += tx;
			t += "</div>";
			document.getElementById('showUpdateIndexName').innerHTML = '';
			document.getElementById('showUpdateIndexName').innerHTML += t;
		},
		error:function(e){
			alert("修改索引名称时查询索引名称异常："+e.status);
		}
	});
}
function updateIndexNameModal(id,name){
	$('#updateIndexName_Modal').modal('show');
	$('#updateIndexNameModal_input').val('');
	$('#updateIndexNameModal_input').val(name);
	$('#updateIndexNameIdModal_input').val('');
	$('#updateIndexNameIdModal_input').val(id);
}
function confirmUpdateIndexName(){

	var updateIndexName_name = $('#updateIndexNameModal_input').val();
	if('' == updateIndexName_name){
		alert("请输入索引名称！");
	}else{
		$('#updateIndexName_Modal').modal('hide');
		$.ajax({
			url:"checkIndexNameSame.action",
			data:{addIndexName:updateIndexName_name},
			dataType:"JSON",
			type:"post",
			success:function(data){
				if(data){
					alert("索引名称“"+updateIndexName_name+"”已经存在，请重新输入！");
				}else{
					//索引名称id
					var id = $('#updateIndexNameIdModal_input').val();
					$.ajax({
						url:"updateIndexName.action",
						data:{id:id,
							searchName:updateIndexName_name},
						dataType:"JSON",
						type:"post",
						success:function(data){
							updateIndexName();
							reLoadIndexName("");
							if(!data)alert("修改失败！");
						},
						error:function(e){
							alert("修改索引名称时异常："+e.status);
						}
					});
				}
			},
			error:function(e){
				alert("修改索引名称时，校验索引名称异常："+e.status);
			}
		})
	}
	
}
//修改索引类型
function updateIndexType(){
	clearAddFrame();
	$('#rightDiv').removeClass('HdClass');
	$('#showUpdateIndexType').removeClass('HdClass');
	$.ajax({
		url:"selectIndexNameWhenDeleteIndexType.action",
		data:"",
		dataType:"JSON",
		type:"post",
		success:function(data){
			var div = "<div style='float:left;width:33.333333333%;'><label style='float:left;padding-top:7px;'>索引名称：</label>"
				+"<div style='float:left;'><select class='selectClass' id='updateIndexType_selectName' onmouseleave='updateIndexType_showIndexType();'>";
			var text = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					text += "<option value='"+obj.id+"'>"+obj.search_name+"</option>";
				});
			}
			div += text;
			div += "</select></div></div>";
			div += "<div style='float:left;width:33.333333333%;'><label style='float:left;padding-top:7px;'>索引类型：</label>"
				+"<div style='float:left;padding-top:0px;cursor:default;' id='updateIndexType_showTypeDiv'></div></div>";
			document.getElementById('showUpdateIndexType').innerHTML = '';
			document.getElementById('showUpdateIndexType').innerHTML += div;
		},
		error:function(e){
			alert("修改索引类型时，查询索引名称异常："+e.status);
		}
	})
}
function updateIndexType_showIndexType(){
	var id = $('#updateIndexType_selectName option:checked').val();
	$.ajax({
		url:"selectIndexTypeWhenDeleteIndexType.action",
		data:{id:id},
		dataType:"json",
		type:"post",
		success:function(data){
			var div='';
			if(data.length>0){
				$.each(data,function(i,obj){
					div += "<div onclick=\"updateIndexType_showModal('"+obj.id+"','"+obj.search_types+"');\">"+obj.search_types+"</div>";
				});
			}else{
				div += "<div style='color:red;'>没有关联的索引类型</div>";
			}
			$('#updateIndexTypeIdModal_input').val("");
			$('#updateIndexTypeIdModal_input').val(id);
			document.getElementById('updateIndexType_showTypeDiv').innerHTML = '';
			document.getElementById('updateIndexType_showTypeDiv').innerHTML += div;
		},
		error:function(e){
			alert("修改索引类型时，查询索引类型异常："+e.status);
		}
	});
}
function updateIndexType_showModal(id,types){
	$('#updateIndexType_Modal').modal('show');
	$('#updateIndexTypeModal_input').val('');
	$('#updateIndexTypeModal_input').val(types);
	$('#updateIndexTypeIdModal_indexTypeId').val('');
	$('#updateIndexTypeIdModal_indexTypeId').val(id);
}
function confirmUpdateIndexType(){

	//var indexName = $('#updateIndexType_selectName');
	var indexType = $('#updateIndexTypeModal_input').val();
	//索引名称id
	var id = $('#updateIndexTypeIdModal_input').val();
	//索引类型id
	var type_id = $('#updateIndexTypeIdModal_indexTypeId').val();
	$.ajax({
		url:"checkIndexTypeSame.action",
		data:{index_id:id,
			indexType:indexType},
		dataType:"json",
		type:"post",
		success:function(data){
			if(data){
				alert("索引类型“"+indexType+"”已经存在，请重新输入。");
			}else{
				
				$.ajax({
					url:"updateIndexType.action",
					data:{id:type_id,
						name_id:id,
						searchType:indexType},
					dataType:"json",
					type:"post",
					success:function(data){
						$('#updateIndexType_Modal').modal('hide');
						updateIndexType_showIndexType();
						if(!data)alert("修改索引类型失败！");
					},
					error:function(e){
						alert("修改索引类型时异常："+e.status);
					}
				})
			}
		},
		error:function(e){
			alert("修改索引类型时验证索引类型异常："+e.status);
		}
	});

	
}
//修改索引标题
function updateIndexTitle(){
	clearAddFrame();
	$('#rightDiv').removeClass('HdClass');
	$('#showUpdateIndexTitle').removeClass('HdClass');
	$.ajax({
		url:"selectIndexNameWhenDeleteIndexType.action",
		data:"",
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引名称：</label></div>"
				+"<div style='float:left'><select class='selectClass' id='updateIndexTitle_indexName' onmouseleave='updateIndexTitle_showIndexType();'>";
			var str = '';
			if(data.length>0){
				$.each(data,function(i,obj){
					str += "<option value='"+obj.id+"'>"+obj.search_name+"</option>";
				});
			}
			t += str;
			t += "</select></div></div>";
			t += "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引类型：</label></div>"
				+"<div style='float:left'><select class='selectClass HdClass' id='updateIndexTitle_indexType' onmouseleave='updateIndexTitle_showIndexTitle();'></select></div></div>";
			//标题
			t += "<div style='float:left;width:33.333333333%'><div style='float:left'><label>索引标题：</label></div>"
				+"<div style='float:left;cursor:default;padding-top:0px;' id='updateIndexTitle_indexTitle'></div></div>";
			document.getElementById('showUpdateIndexTitle').innerHTML = '';
			document.getElementById('showUpdateIndexTitle').innerHTML += t;
		},
		error:function(e){
			alert("修改索引标题时查询索引名称异常："+e.status);
		}
	});
}
function updateIndexTitle_showIndexType(){
	var nameId = $("#updateIndexTitle_indexName option:checked").val();
	$.ajax({
		url:"selectIndexTypeWhenDeleteIndexType.action",
		data:{id:nameId},
		dataType:"JSON",
		type:"post",
		success:function(data){
			var t = "";
			
			if(data.length>0){
				$.each(data,function(i,obj){
					t += "<option value='"+obj.id+"'>"+obj.search_types+"</option>";
				});
			}else{
				t += "<option value=''>没有关联的索引类型</option>"
			}
			$('#updateIndexTitle_indexType').removeClass('HdClass');
			document.getElementById('updateIndexTitle_indexType').innerHTML = '';
			document.getElementById('updateIndexTitle_indexType').innerHTML += t;
			document.getElementById('updateIndexTitle_indexTitle').innerHTML = '';
		},
		error:function(e){
			alert("修改索引标题时查询索引类型异常："+e.status);
		}
	});
}
function updateIndexTitle_showIndexTitle(){
	var typeId = $("#updateIndexTitle_indexType option:checked").val();
	if(null != typeId && '' != typeId){
		$.ajax({
			url:"selectIndexTitleByPid.action",
			data:{id:typeId},
			dataType:"JSON",
			type:"post",
			success:function(data){
				var t = '';
				if(data.length>0){
					$.each(data,function(i,obj){
						t += "<div onclick=showIndexFieldPermission('"+obj.pid+"','"+obj.search_title+"','u')>"+obj.search_title+"</div>";
					});
				}else{
					t += "<div style='color:red'>没有关联的索引标题</div>";
				}
				document.getElementById('updateIndexTitle_indexTitle').innerHTML = '';
				document.getElementById('updateIndexTitle_indexTitle').innerHTML += t;
			},
			error:function(e){
				alert("修改索引标题时查询索引标题异常："+e.status);
			}
		});
	}
}
function confirmUpdateTitleButton(){

	var now_title = $('#updateIndexTitleInputModal').val();
	var old_title = $('#updateIndexTitle_oldTitle').val();
	//索引标题的pid
	var old_pid = $('#updateIndexTilte_oldPid').val();
	var field = '';
	var fieldType = '';
	$("#addIndexFT2 div input:checked").each(function(){
		field += $(this).val()+",";
		fieldType += $("#"+$(this).val()).val()+",";
	})
	document.getElementById('updateIndexTitle_showExit').innerHTML = '';
	if('' == now_title){
		alert("请输入索引标题");
	}else if('' == field){
		alert("请勾选索引类型");
	}else if(now_title == old_title){
		$('#myModalshow').modal('hide');
		$.ajax({
			url:"updateIndexTitle.action",
			data:{pid:old_pid,
				now_title:now_title,
				old_title:old_title,
				field:field,
				fieldType:fieldType},
			dataType:"json",
			type:"post",
			success:function(data2){
				if(data2){
					updateIndexTitle_showIndexTitle();
					justClearAddIndexFrame();
				}else{
					alert("修改索引标题失败！");
				}
			},
			error:function(e){
				alert("修改索引标题时异常");
			}
		});
	}else{
		//alert(field+":"+fieldType);
		$.ajax({
			url:"selectTheSameTitle.action",
			data:{id:old_pid,
				title:now_title},
			dataType:"json",
			type:"post",
			success:function(data){
				if(data){
					document.getElementById('updateIndexTitle_showExit').innerHTML = "<font color='red'>索引名称已经存在，请重新输入。</font>";
				}else{
					$('#myModalshow').modal('hide');
					$.ajax({
						url:"updateIndexTitle.action",
						data:{pid:old_pid,
							now_title:now_title,
							old_title:old_title,
							field:field,
							fieldType:fieldType},
						dataType:"json",
						type:"post",
						success:function(data2){
							if(data2){
								updateIndexTitle_showIndexTitle();
								justClearAddIndexFrame();
							}else{
								alert("修改索引标题失败！");
							}
						},
						error:function(e){
							alert("修改索引标题时异常");
						}
					});
				}
			},
			error:function(e){
				alert("修改索引标题时，检查索引标题异常："+e.status);
			}
		});
	}

}
function searchIndexName_button(v){
	var text = $("#searchIndexName_input").val();
	if(1 == v && '' == text){
		reLoadIndexName(text);
	}
	if(2 == v){
		reLoadIndexName(text);
	}
}
function deleteIndexNameTypeTitle(){
	var type = $("#deleteNameTypeTitle_inputV").val();
	if(1 == type){
		deleteIndexNameData2();
	}
	if(2 == type){
		deleteIndexTypeData2();
	}
	if(3 == type){
		deleteIndexTitle_delete2();
	}
}

/*$(function(){
	
	$('#operationModal').modal({
		backdrop:'static',
		keyboard:false
	});
	$('#operationModal').modal('hide');
	
})*/
	
	
